/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Email;

import Records.RecordsMain;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Alexander
 */
public class SendEmail {

    static String emailText;
    static String subjectText;

    public SendEmail() {
        emailText = "Feedback: " + RecordsMain.dialog.exDescription.getText();
        subjectText = "User Feedback: " + RecordsMain.dialog.subjectLine.getText();
    }

    public void Send() {
        System.out.println("SendEmail.Send()");
        String Email = "RecordsFeedback@gmail.com";
        final String username = "RecordsFeedback@gmail.com";
        final String key = "recdebug";

        Properties props = new Properties();
        props.put("mail.smtp.starttls.enable", "true");
        props.put("mail.smtp.auth", "true");
        props.put("mail.smtp.host", "smtp.gmail.com");
        props.put("mail.smtp.port", "587");

        Session session = Session.getInstance(props,
                new javax.mail.Authenticator() {
                    protected PasswordAuthentication getPasswordAuthentication() {
                        return new PasswordAuthentication(username, key);
                    }
                });

        Message message = new MimeMessage(session);
        try {
            message.setFrom(new InternetAddress(username));
            //Students Email Should go here
            message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(Email));
            message.setSubject(subjectText);
            message.setText(emailText);

            Transport.send(message);
            System.out.println("Email Sent!");
        } catch (MessagingException ex) {
            Logger.getLogger(SendEmail.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
